package com.aixin.csopuser.domain;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import javax.persistence.*;
import java.io.Serializable;
import java.time.Instant;
import java.util.Date;
import java.util.Set;

@Data
@ToString
@Entity
@NoArgsConstructor
@Table(name = "customer")
public class CustomerDomain implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @Column(name = "customerID", length = 32)
    private String customerID;//客户ID

    @Column(name = "custName", length = 32)
    private String custName;//客户姓名

    @Column(name = "gender")
    private Integer gender;//性别

    @Column(name = "phoneNumber", length = 11)
    private String phoneNumber;//手机号

    @Column(name = "certID", length = 32)
    private String certID;//证件号

    @Column(name = "certType", length = 11)
    private String certType;//证件类型

    @Column(name = "custStatus")
    private Integer custStatus;//客户状态

    @Column(name = "firstEffTime")
    private Instant firstEffTime;//首单生效时间

    @Column(name = "lastUseTime")
    private Instant lastUseTime;//最近使用时间

    @Column(name = "usedPoint")
    private Integer usedPoint;//已用积分

    @Column(name = "remnPoint")
    private Integer remnPoint;//可用积分

    @Column(name = "agentCode", length = 32)
    private String agentCode;//规划师

    @Column(name = "agentName", length = 32)
    private String agentName;//规划师姓名

    @Column(name = "agentAgency", length = 32)
    private String agentAgency;//规划师所输机构

    @Column(name = "agentPhoneNumber", length = 32)
    private String agentPhoneNumber;//规划师手机号

    @Column(name = "createTime", length = 45)
    private Instant createTime;//创建时间

    @Column(name = "updateTime", length = 45)
    private Instant updateTime;
    @Column(name = "birthday", length = 45)
    private Date birthday;//出生日期

    @Column(name = "customerType")
    private Integer customerType;//1: 投保人 2: 被保人

//    @ManyToOne(fetch = FetchType.LAZY)
//    @JoinColumn(name = "agentCode", nullable = false, insertable = false, updatable = false)
//    @NotFound(action = NotFoundAction.IGNORE)
    @Transient
    @JsonSerialize
    private AgentInfo agentInfo;

    @OneToMany(fetch = FetchType.LAZY)
    @JoinColumn(name = "customerID")
    @JsonIgnoreProperties(value = "customer", allowSetters = true)
    @NotFound(action = NotFoundAction.IGNORE)
    private Set<CustomerEquity> customerEquities;

    public CustomerDomain(String customerID,
                          String custName,
                          String phoneNumber,
                          String certID,
                          Integer gender,
                          Instant firstEffTime) {
        this.customerID = customerID;
        this.custName = custName;
        this.phoneNumber = phoneNumber;
        this.certID = certID;
        this.gender = gender;
        this.firstEffTime = firstEffTime;
    }
}
